﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using Tesla.Validador;

namespace Rendiciones.Logica.Modelos.Validaciones
{
    internal class NoPuedeEstarEnBlanco : ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
                return new UsefullValidationResult(new[] { validationContext.MemberName }, EValidationResolution.Success);

            if (value is string)
            {
                var valor = (string) value;
                if (string.IsNullOrEmpty(valor))
                    return new UsefullValidationResult(new[] {validationContext.MemberName}, EValidationResolution.Error,
                                                       ErrorMessage);
                return new UsefullValidationResult(new[] {validationContext.MemberName}, EValidationResolution.Success);
            }
            else
            {
                if(string.IsNullOrEmpty(value.ToString()))
                    return new UsefullValidationResult(new[] {validationContext.MemberName}, EValidationResolution.Error);
                else
                    return new UsefullValidationResult(new[] { validationContext.MemberName }, EValidationResolution.Success);
            }

        }
    }
}